home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / pcb121.zip / SLIP.INC < prev    next >
Text File  |  1992-01-23  |  10KB  |  287 lines

  1. ;;******************************************************************************
  2. ;;                         slip.inc      slip.inc
  3. ;;******************************************************************************
  4. ;;
  5. ;;  Copyright (C) 1989 Vance Morrison
  6. ;;
  7. ;;
  8. ;; Permission to view, compile, and modify for LOCAL (intra-organization) 
  9. ;; USE ONLY is hereby granted, provided that this copyright and permission 
  10. ;; notice appear on all copies.  Any other use by permission only.
  11. ;;
  12. ;; Vance Morrison makes no representations about the suitability 
  13. ;; of this software for any purpose.  It is provided "as is" without expressed 
  14. ;; or implied warranty.  See the copywrite notice file for complete details.
  15. ;;
  16. ;;******************************************************************************
  17. ;; slip.inc contains the interface driver for a SLIP interface.  This
  18. ;; software is responcible for packetizing/depacketizing the data for the
  19. ;; serial line and providing data transparency (byte stuffing)
  20. ;;
  21. ;; The functions provided by this file are
  22. ;;
  23. ;;   SLIP_DECLARE name, i8250, rbuff, rqueue, wbuff, wqueue
  24. ;;   SLIP_DEFINE name
  25. ;;   SLIP_CONSUME_in_AL_const_BX_BP_ES name
  26. ;;   SLIP_WRITE_EMPTY_const_BX_BP_ES name
  27. ;;   SLIP_WRITE_const_BX_BP_ES name
  28. ;;
  29. ;; This code assumes that an i8250 interface (WRITE and CAN_WRITE) 
  30. ;; is available via the 'i8250' variable passed to SLIP_DECLARE
  31. ;;
  32. ;;   slip_&name&_declared                  ;; one if this interface exists
  33. ;;   if_&name&_mtu                         ;; the maximum transmition unit
  34. ;;   if_&name&_address                     ;; physical address (dummy value)
  35. ;;
  36. ;;******************************************************************************
  37.  
  38. ;;******************************************************************************
  39. ;; data storage needed by this module
  40.  
  41. slip_data  STRUC
  42.     slip_rptr   DW 0 
  43.     slip_rstart DW 0 
  44.     slip_rend   DW 0 
  45.     slip_resc   DB 0 
  46.     slip_rsyncing DB 0 
  47.     slip_wptr   DW 1        ; bigger than wend means start a new packet
  48.     slip_wend   DW 0 
  49.     slip_drops  DW 0        ; number of dropped packets
  50.     slip_bytes_in DW 0      ; total number of bytes that have come in
  51.     slip_bytes_out DW 0         ; total number of bytes that have went out
  52.     slip_wesc   DB 0 
  53.     slip_w_idle DB 1        ;; flag set when 8250 write buff idle
  54. slip_data ENDS
  55.  
  56. SLIP_ESC = 0DBH
  57. SLIP_END = 0C0H
  58. SLIP_ESC_ESC = 0DDH
  59. SLIP_ESC_END = 0DCH
  60.  
  61.  
  62. ;;******************************************************************************
  63. ;;  SLIP_DECLARE 
  64.  
  65. SLIP_DECLARE MACRO name, i8250, rbuff, rqueue, wbuff, wqueue
  66.     .errb <name>
  67.     .errb <wqueue>
  68.  
  69.     .DATA
  70.     slip_&name&_declared     = 1
  71.     slip_&name&_i8250        = i8250
  72.     slip_&name&_rbuff        = rbuff
  73.     slip_&name&_rqueue       = rqueue
  74.     slip_&name&_wbuff        = wbuff
  75.     slip_&name&_wqueue       = wqueue
  76.  
  77.     if_&name&_mtu = 1006
  78.  
  79.     global slip_&name&_data:slip_data
  80.     global if_&name&_address:byte
  81.     .CODE
  82. ENDM
  83.  
  84.  
  85. ;;******************************************************************************
  86. ;;   SLIP_DEFINE name
  87. ;;      sets asside memory the named object and initializes it.  This
  88. ;;      routine is a no-op if 'name' was not declared.  It jumps to 'fail'
  89. ;;      if there was an error in  setup.
  90. ;;
  91. SLIP_DEFINE MACRO name
  92. ifdef slip_&name&_declared
  93.     .DATA
  94.     slip_&name&_data    slip_data      <>  ;; create storage needed
  95.     if_&name&_address   DB 6 DUP (0)
  96.  
  97.     .CODE
  98.     mov slip_&name&_data.slip_w_idle, 1
  99. endif
  100. ENDM
  101.  
  102.  
  103. ;;******************************************************************************
  104. ;; SLIP_WRITE_EMPTY_const_BX_BP_ES is called at interupt level whenever a
  105. ;; character can be written.  
  106.  
  107. SLIP_WRITE_EMPTY_const_BX_BP_ES MACRO name
  108.     local done, write_char, no_char
  109.  
  110.     write_char:
  111.     SLIP_GETQUEUE_out_AL_const_BX_BP_ES name, no_char
  112.     inc slip_&name&_data.slip_bytes_out
  113.     I8250_WRITE_in_AL_const_BX_BP_ES %slip_&name&_i8250 
  114.     I8250_CAN_WRITE_const_BX_CX_BP_SI_DI_ES %slip_&name&_i8250, done
  115.     jmp write_char
  116.     no_char:
  117.     mov slip_&name&_data.slip_w_idle, 1 
  118.     done:
  119. ENDM
  120.  
  121.  
  122. ;;******************************************************************************
  123. ;; SLIP_WRITE is called whenever a high level write is 
  124. ;; performed (something is placed in the queue).  The call to this routine
  125. ;; acts as a 'trigger' that starts the writing if it is not already in 
  126. ;; progress.
  127.  
  128. SLIP_WRITE_const_BX_BP_ES MACRO name
  129.     local done, write_char, no_char, cant_write
  130.  
  131.     cmp slip_&name&_data.slip_w_idle, 0     ;; are we idle
  132.     jz done
  133.     write_char:
  134.         SLIP_GETQUEUE_out_AL_const_BX_BP_ES name, done
  135.         inc slip_&name&_data.slip_bytes_out
  136.         I8250_WRITE_in_AL_const_BX_BP_ES %slip_&name&_i8250 
  137.         I8250_CAN_WRITE_const_BX_CX_BP_SI_DI_ES %slip_&name&_i8250, cant_write
  138.         jmp write_char
  139.     cant_write:
  140.     mov slip_&name&_data.slip_w_idle, 0
  141.     done:
  142. ENDM
  143.  
  144.  
  145. ;;******************************************************************************
  146. ;; SLIP_CONSUME is called from the interupt routine whenever a new character
  147. ;; is available from this interface.  The character is in AL.  SLIP_CONSUME's
  148. ;; job is to place it in the packet queue.
  149.  
  150. SLIP_CONSUME_in_AL_const_BX_BP_ES MACRO name
  151.     inc slip_&name&_data.slip_bytes_in
  152.     SLIP_PUTQUEUE_in_AL_const_const_BX_BP_ES name   ; easy is't it?
  153. ENDM
  154.  
  155.  
  156. ;;******************************************************************************
  157. ;; puts a chacacter read in for interface 'name' into the read queue 
  158.  
  159. SLIP_PUTQUEUE_in_AL_const_const_BX_BP_ES MACRO name 
  160.    local cont_packet, done, not_escaped, try_esc_esc, got_end, got_esc
  161.    local drop, not_end, nobuff
  162.  
  163.    mov SI, slip_&name&_data.slip_rptr
  164.    or SI, SI                            ;; rptr = 0 if 'between' packets
  165.    jnz cont_packet
  166.        cmp AL, SLIP_END
  167.        jnz not_end
  168.            mov slip_&name&_data.slip_rsyncing, 0
  169.            jmp done
  170.        not_end:
  171.        cmp slip_&name&_data.slip_rsyncing, 0
  172.        jnz done
  173.        mov CX, if_&name&_mtu
  174.        mov DX, AX
  175.        BUFF_CHECK_in_CX_out_SI_DI_const_BX_CX_DX_BP_ES %slip_&name&_rbuff,nobuff
  176.        mov AX, DX
  177.        mov slip_&name&_data.slip_rptr, SI
  178.        mov slip_&name&_data.slip_rstart, SI
  179.        mov slip_&name&_data.slip_rend, DI
  180.        BUFF_GET_in_DI_const_AX_BX_CX_DX_BP_SI_DI_ES %slip_&name&_rbuff
  181.    cont_packet:
  182.        cmp AL, SLIP_END
  183.        jz got_end
  184.        cmp AL, SLIP_ESC
  185.        jz got_esc
  186.        ;; what to do if you have a regular character
  187.        cmp slip_&name&_data.slip_resc, 0
  188.        jz not_escaped
  189.            mov slip_&name&_data.slip_resc, 0
  190.            cmp AL, SLIP_ESC_END
  191.            jnz try_esc_esc
  192.            mov AL, SLIP_END
  193.            jmp not_escaped
  194.            try_esc_esc:
  195.            cmp AL, SLIP_ESC_ESC
  196.            jnz drop
  197.            mov AL, SLIP_ESC
  198.        not_escaped:
  199.            mov CX, slip_&name&_data.slip_rstart
  200.            add CX, if_&name&_mtu
  201.            cmp SI, CX
  202.            jae drop 
  203.            mov [SI], AL
  204.            inc SI
  205.            mov slip_&name&_data.slip_rptr, SI
  206.            jmp done
  207.        drop:
  208.            mov DI,slip_&name&_data.slip_rend
  209.            BUFF_FREE_in_DI_const_AX_BX_CX_DX_BP_SI_DI_ES %slip_&name&_rbuff
  210.        nobuff:
  211.            mov slip_&name&_data.slip_rptr, 0
  212.            mov slip_&name&_data.slip_resc, 0
  213.            mov slip_&name&_data.slip_rsyncing, 1
  214.            inc slip_&name&_data.slip_drops
  215.            jmp done
  216.        got_esc:
  217.            mov slip_&name&_data.slip_resc, 1
  218.            jmp done
  219.        got_end:
  220.        mov CX, SI
  221.        mov AX, slip_&name&_data.slip_rstart
  222.        sub CX, AX
  223.        mov SI, AX
  224.        QUEUE_ENQUEUE_out_DI_const_BX_CX_DX_BP_SI_ES %slip_&name&_rqueue, drop 
  225.        mov [DI+0], SI                   ;; offset for start ptr
  226.        mov DX, slip_&name&_data.slip_rend
  227.        mov [DI+2], DX                   ;; offset for end ptr
  228.        mov [DI+4], CX                   ;; offset for data len (may be less)
  229.        mov slip_&name&_data.slip_rptr, 0
  230.     done:
  231. ENDM
  232.  
  233.  
  234. ;;******************************************************************************
  235. ;; 
  236. SLIP_GETQUEUE_out_AL_const_BX_BP_ES MACRO name, no_char
  237.    local cont_packet, end_packet, done, normal_char, check_esc, update_ptr
  238.  
  239.    mov SI, slip_&name&_data.slip_wptr
  240.    cmp SI, slip_&name&_data.slip_wend
  241.    jb cont_packet
  242.    jz end_packet
  243.        QUEUE_HEAD_out_SI_const_AX_BX_CX_DX_BP_DI_ES %slip_&name&_wqueue, no_char
  244.        mov DI, SI
  245.        mov SI, [DI+0]                   ;; get start ptr
  246.        mov slip_&name&_data.slip_wptr, SI
  247.        mov AX, [DI+4]                   ;; get data len
  248.        add AX, SI
  249.        mov slip_&name&_data.slip_wend, AX
  250.        mov AL, SLIP_END
  251.        jmp done
  252.    end_packet:
  253.        mov AL, SLIP_END
  254.        inc SI
  255.        mov slip_&name&_data.slip_wptr, SI
  256.        QUEUE_HEAD_out_SI_const_AX_BX_CX_DX_BP_DI_ES %slip_&name&_wqueue, done
  257.        mov DI, [SI+2]                   ;; get end ptr
  258.        BUFF_FREE_in_DI_const_AX_BX_CX_DX_BP_SI_DI_ES %slip_&name&_wbuff
  259.        QUEUE_DEQUEUE_in_SI_const_AX_BX_CX_DX_BP_DI_ES %slip_&name&_wqueue
  260.        jmp done
  261.    cont_packet:
  262.        cmp slip_&name&_data.slip_wesc, 0
  263.        jz normal_char
  264.        mov AL, slip_&name&_data.slip_wesc
  265.        mov slip_&name&_data.slip_wesc, 0
  266.        jmp update_ptr
  267.    normal_char:
  268.        mov AL, [SI]
  269.        cmp AL, SLIP_END
  270.        jnz check_esc
  271.        mov slip_&name&_data.slip_wesc, SLIP_ESC_END
  272.        mov AL, SLIP_ESC
  273.        jmp done
  274.        check_esc:
  275.        cmp AL, SLIP_ESC
  276.        jnz update_ptr
  277.        mov slip_&name&_data.slip_wesc, SLIP_ESC_ESC
  278.        mov AL, SLIP_ESC
  279.        jmp done
  280.   update_ptr:
  281.        inc SI
  282.        mov slip_&name&_data.slip_wptr, SI
  283.    done:
  284.  
  285. ENDM
  286.  
  287.